const fs = require('fs')
const path = require('path')
const http = require('http')
const server = http.createServer()

// 监听收到的请求
server.on('request', (request, response) => {
    // 判断请求资源路径
    if (request.url === '/index.html') {
        fs.readFile(path.join(__dirname, 'File/zip.html'), (error, data) => {
            if (error) console.log(error)
            else {
                response.setHeader('Content-Type', 'text/html;charset=utf-8')
                response.end(data.toString())
            }
        })

    }else {
        // 其他路径：访问的资源不存在
        response.setHeader('Content-Type','text/plain;charset=utf-8')
        response.end('访问的资源不存在')
    }
})

server.listen(8080,() => {
    console.log('Web服务已启动...')
})